import React, { useReducer, useState } from 'react'
// 格式useReducer传入一个对象和函数
// 函数return出对象 获取type的时候是acyion.type
// ditpatch传入对象key是type
export default function Page4() {
  const [state,ditpatch]=useReducer(ui,{count:1})
  function ui(stateq,action){
    if(action.type==='increase'){
       return {...stateq,count:stateq.count+1}
    }else if(action.type==='decrease'){
        return {...stateq,count:stateq.count-1}
    }
  }
  return (
    <div>
        <div>useReducer的使用</div>
        <div>{state.count}</div>
        <button onClick={()=>{ditpatch({type:'increase'})}}>+1</button>
        <button onClick={()=>{ditpatch({type:'decrease'})}}>-1</button>
    </div>
  )
}
